package cn.com.ghy.android.bean;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import org.xmlpull.v1.XmlPullParser;

import android.util.Xml;

/**
 * @软件著作权:金红叶纸业集团有限公司
 * @系统名称:SFA系统
 * @Description:拜访信息页面下拉框信息解析类
 * @author wuz  @date 2011-5-27 14:27:36
 * @版本历史:v1.0
 * @Copyright:Copyright (c) 2011-2012 
 */

public class DataCollVisitComboxBeanParser {
	public static List<DataCollVisitComboxBean> parseXML(InputStream in) throws Exception {
        XmlPullParser parser = Xml.newPullParser();
        parser.setInput(in, "UTF-8");
        int type = parser.getEventType(); 
        
        DataCollVisitComboxBean bean = null;
        List<DataCollVisitComboxBean> list = null;
        
        List<UnitInfoBean> unitInfoList = null;
        UnitInfoBean unitInfo = null;
        
    	List<CompeteBrandInfoBean> competeBrandInfoList = null;
    	CompeteBrandInfoBean competeBrandInfoBean = null;
    	
    	List<SaleTypeBean> saleTypeList = null;
    	SaleTypeBean saleTypeBean = null;
    	
    	List<DisplaySiteBean> displaySiteList = null;
    	DisplaySiteBean displaySiteBean = null;
    	
    	List<PictureTypeBean> pictureTypeList = null;
    	PictureTypeBean pictureTypeBean = null;
    	
    	List<GoodsTypeBean> goodsTypeList = null;
    	GoodsTypeBean goodsTypeBean = null;
        
        while (type != XmlPullParser.END_DOCUMENT) { 
            switch (type) {   
            case XmlPullParser.START_DOCUMENT:   
            	list = new ArrayList<DataCollVisitComboxBean>();
            	unitInfoList = new ArrayList<UnitInfoBean>();
            	competeBrandInfoList = new ArrayList<CompeteBrandInfoBean>();
            	saleTypeList = new ArrayList<SaleTypeBean>();
            	displaySiteList = new ArrayList<DisplaySiteBean>();
            	pictureTypeList = new ArrayList<PictureTypeBean>();
            	goodsTypeList = new ArrayList<GoodsTypeBean>();
                break;   
   
            case XmlPullParser.START_TAG:
                if ("NewDataSet".equals(parser.getName())) {
                	bean = new DataCollVisitComboxBean();
                } else if (null != list && null != bean) {
                	if ("comb_unit".equals(parser.getName())) {
                    	unitInfo = new UnitInfoBean();
                    } else if (null != unitInfo) {
                        if ("UNIT".equals(parser.getName())) {   
                        	unitInfo.setUnit(parser.nextText());   
                        } else if("UNITNAME".equals(parser.getName())) {
                        	unitInfo.setUnitname(parser.nextText());
                        }
                    }   
                	
                	if ("comb_jp".equals(parser.getName())) {
                		competeBrandInfoBean = new CompeteBrandInfoBean();
                    } else if (null != competeBrandInfoBean) {
                        if ("JP".equals(parser.getName())) {   
                        	competeBrandInfoBean.setJp(parser.nextText());   
                        } else if("JPNAME".equals(parser.getName())) {
                        	competeBrandInfoBean.setJpname(parser.nextText());
                        } else if("STATE".equals(parser.getName())) {
                        	competeBrandInfoBean.setState(parser.nextText());
                        }
                    }
                	
                	if ("comb_jg".equals(parser.getName())) {
                		saleTypeBean = new SaleTypeBean();
                    } else if (null != saleTypeBean) {
                        if ("JG".equals(parser.getName())) {   
                        	saleTypeBean.setJg(parser.nextText());   
                        } else if("JGNAME".equals(parser.getName())) {
                        	saleTypeBean.setJgname(parser.nextText());
                        }
                    }   
                	
                	if ("comb_clwz".equals(parser.getName())) {
                		displaySiteBean = new DisplaySiteBean();
                    } else if (null != displaySiteBean) {
                        if ("CLWZ".equals(parser.getName())) {   
                        	displaySiteBean.setClwz(parser.nextText());   
                        } else if("CLWZNAME".equals(parser.getName())) {
                        	displaySiteBean.setClwzname(parser.nextText());
                        }
                    }   
                	
                	if ("comb_pictype".equals(parser.getName())) {
                		pictureTypeBean = new PictureTypeBean();
                    } else if (null != pictureTypeBean) {
                        if ("PICTYPE".equals(parser.getName())) {   
                        	pictureTypeBean.setPictype(parser.nextText());   
                        } else if("PICTYPENAME".equals(parser.getName())) {
                        	pictureTypeBean.setPictypename(parser.nextText());
                        }
                    }   
                	
                	if ("comb_pl".equals(parser.getName())) {
                		goodsTypeBean = new GoodsTypeBean();
                    } else if (null != goodsTypeBean) {
                        if ("PLID".equals(parser.getName())) {   
                        	goodsTypeBean.setPlid(parser.nextText());   
                        } else if("PLNAME".equals(parser.getName())) {
                        	goodsTypeBean.setPlname(parser.nextText());
                        }
                    }   
                }   
                break;   
   
            case XmlPullParser.END_TAG : 
            	if ("comb_unit".equals(parser.getName())) {
                	if(null != unitInfo) {
                		unitInfoList.add(unitInfo);
                		unitInfo = null;
                	}
                	break;
                }
            	
            	if ("comb_jp".equals(parser.getName())) {
                	if (null != competeBrandInfoBean) {
                		competeBrandInfoList.add(competeBrandInfoBean);
                		competeBrandInfoBean = null;
                	}
                	break;
                }
            	
            	if ("comb_jg".equals(parser.getName())) {
                	if (saleTypeBean != null) {
                		saleTypeList.add(saleTypeBean);
                		saleTypeBean = null;
                	}
                	break;
                }
            	
            	if ("comb_clwz".equals(parser.getName())) {
                	if (displaySiteBean != null) {
                		displaySiteList.add(displaySiteBean);
                		displaySiteBean = null;
                	} 
                	break;
                }
            	
            	if ("comb_pictype".equals(parser.getName())) {
                	if (pictureTypeBean != null) {
                		pictureTypeList.add(pictureTypeBean);
                		pictureTypeBean = null;
                	} 
                	break;
                }
            	
            	if ("comb_pl".equals(parser.getName())) {
                	if (goodsTypeBean != null) {
                		goodsTypeList.add(goodsTypeBean);
                		goodsTypeBean = null;
                	}
                	break;
                }
            	
                if ("NewDataSet".equals(parser.getName())) {
                	if (null != list && bean != null) {
                		bean.setUnitInfoList(unitInfoList);
                		bean.setCompeteBrandInfoList(competeBrandInfoList);
                		bean.setDisplaySiteList(displaySiteList);
                		bean.setPictureTypeList(pictureTypeList);
                		bean.setSaleTypeList(saleTypeList);
                		bean.setGoodsType(goodsTypeList);
                		list.add(bean);
                		bean = null;
                	} 
                }
                break;
            }
            type = parser.next();
        }   
        in.close();   
        return list;  
    }
}
